package com.smartstate.ems.timedtask;

import cn.hutool.core.date.DateField;
import cn.hutool.core.date.DateTime;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class AsyncMinuteSummaryTask {

    @Autowired
    private AsyncSummaryTaskService asyncSummaryTaskService;




    /**
     * 每半小时进行数据统计
     */
    @Async
//    @Scheduled(cron = "*/1 * * * * ?")
    @Scheduled(cron = "0 5,35 * * * ?")
    public void async30MinuteSummaryTask() {
        DateTime dateTime = new DateTime();
        DateTime startDate = dateTime.offsetNew(DateField.MINUTE, -35);
        DateTime endDate = dateTime.offsetNew(DateField.MINUTE, -5);
        log.info("半小时数据统计定时任务开始>>>>>" + dateTime.toString());
        boolean b = asyncSummaryTaskService.summaryTask30Minute(startDate, endDate);
        log.info(endDate.toString() + "半小时数据统计定时任务完成>>>>>" + b);
    }
//    /**
//     * 每天晚十一点25进行明天半小时作息生成
//     */
//    @Async
//    @Scheduled(cron = "0 15 23 * * ?")
//    public void createHalfAnHour() {
//        DateTime dateTime = new DateTime();
//        DateTime date = dateTime.offsetNew(DateField.HOUR, 4);
//        logger.info("进行明天半小时作息生成定时任务开始>>>>>" + new Date());
//        boolean b = remoteMainService.createHalfAnHour(date);
//        logger.info(date.toDateStr() + "半小时作息生成定时任务完成>>>>>" + b);
//
//    }
//
//
//    /**
//     * 每周五晚十点生成下周作息
//     */
//    @Async
//    @Scheduled(cron = "0 20 23 ? * 7")
//    public void asyncEveryDaySummaryTask() {
//        Date dateTime = new DateTime();
//        DateTime offset = cn.hutool.core.date.DateUtil.offset(dateTime, DateField.HOUR, 10);
//        boolean b = remoteMainService.asyncEveryDaySummaryTask(offset);
//        logger.info(offset.toDateStr() + "周作息生成定时任务完成>>>>>" + b);
//    }


}
